package org.kzwl.book.controller.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.kzwl.comm.pojo.ResponseData;
import org.kzwl.comm.pojo.bo.book.BookQueryBasic;
import org.kzwl.comm.pojo.bo.book.QueryTitleBO;
import org.kzwl.comm.pojo.dto.book.BookDTO;
import org.kzwl.comm.pojo.dto.book.BookDetailsDTO;
import org.kzwl.comm.pojo.dto.book.HotOrNewDTO;
import org.kzwl.entity.app.Book;
import org.kzwl.service.app.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/webBook")
@Api("PC图书")
public class WebBookController {

    @Autowired
    private BookService bookService;

    @ApiOperation(value = "根据分类查询书籍",notes = "cuBookCategoryId(分类编号)--必填 current(当前页数)--必填 size(每页多少条)--选填")
    @PostMapping("/queryBookByType")
    public ResponseData<IPage<BookDTO>> queryBookByType(@RequestBody BookQueryBasic bo) {
        IPage<BookDTO> list = bookService.queryBookByType(bo);
        return new ResponseData<>(list);
    }

    @ApiOperation(value = "查询书籍详情",notes = "cuUserId(用户编号)--必填 cuBookId(图书编号)--必填")
    @PostMapping("/getBook")
    public ResponseData<BookDetailsDTO> getBook(@RequestBody BookQueryBasic bo) {
        BookDetailsDTO dto = bookService.getBook(bo);
        return new ResponseData<>(dto);
    }

    @ApiOperation(value = "热门搜索")
    @PostMapping("/getHot")
    public ResponseData<List<BookDTO>> getHot() {
        List<BookDTO> dto = bookService.getHot();
        return new ResponseData<>(dto);
    }

    @ApiOperation(value = "关键搜索")
    @PostMapping("/queryTitle")
    public ResponseData<List<BookDTO>> queryTitle(@RequestBody QueryTitleBO bo) {
        List<BookDTO> dto = bookService.queryTitle(bo);
        return new ResponseData<>(dto);
    }
}
